package fr.jade.fraclite;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.factory.Factory;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;

import fr.jade.fraclite.factory.BasicGenericFactory;
import fr.jade.fraclite.type.BasicTypeFactory;


public class FracLite implements Factory {

  /**
   * The bootstrap component.
   */
  private static Component bootstrapComponent;

  protected static boolean cacheBootstrapComponent = false;
  
  public static final String DEFAULT_CONFIGURATION_FILE_NAME = "FracLite.xml";
  
  // -------------------------------------------------------------------------
  // Implementation of the Factory interface
  // -------------------------------------------------------------------------

  /**
   * @return <tt>null</tt>.
   */
  public Type getFcInstanceType () {
    return null;
  }

  /**
   * @return <tt>null</tt>.
   */
  public Object getFcControllerDesc () {
    return null;
  }

  /**
   * @return <tt>null</tt>.
   */
  public Object getFcContentDesc () {
    return null;
  }

  public Component newFcInstance () {
    if(cacheBootstrapComponent && bootstrapComponent != null){
      return bootstrapComponent;
    }
    BasicTypeFactory typeFactory = new BasicTypeFactory();
    BasicGenericFactory genericFactory = new BasicGenericFactory();
    genericFactory.weaveableTF = typeFactory;
    Component c = null;
    try {
    // use the pre bootstrap component to create the real bootstrap component
    ComponentType t = typeFactory.createFcType(new InterfaceType[0]);
    c = genericFactory.newFcInstance(t, "bootstrap", null);
    if(cacheBootstrapComponent){
      bootstrapComponent = c;
    }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }
    return c;
  }

}
